<?php

class NewsPostController extends Controller
{
    public function initialise() {}
    
    public function Create($args=null) {
        $session = Session::inst();
        if ($session->user && $session->user->hasRoleAccess("CreateNewsPost"))
        {
            if (isset($_POST["fSubmit"]))
            {
                $object = new NewsPost();
                $object->title = $_POST["title"];
                $object->body = $_POST["body"];
                $object->userid = $session->getUserid();
                
                if ($object->create())
                {
                    $this->view->registerTemplate("system/notification");
                    $this->view->registerVariable("News post successfully created", "notification");
                    $this->CMM->registerControllerIntoChain("home", "main");
                }
                else
                {
                    $this->view->registerTemplate("system/notification");
                    $this->view->registerVariable("Could not create news post", "notification");
                    $this->view->registerVariable("red", "colour");
                    $this->CMM->registerControllerIntoChain("home", "main");
                }
            }
            else
            {
                ViewManager::inst()->registerScript('bbcodeparser');
                ViewManager::inst()->registerScript('jquery.flash');
                ViewManager::inst()->registerScript('jquery.jqUploader');
                $this->view->registerTemplate("newspost/create");
                $this->view->registerVariable(URL("NewsPost", "Create"), "ActionURL");
                $this->view->registerVariable("", "currentBBCode");
            }
        }
        else
        {
            $this->view->registerTemplate("system/notification");
            $this->view->registerVariable("You are not authorized to create a news post.", "notification");
            $this->view->registerVariable("red", "colour");
            $this->CMM->registerControllerIntoChain("home", "main");
        }
    }
}

?>
